/**
 * 
 */
package com.thor.palmmall.rest.servicebill.converter;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.UCN;
import com.thor.commons.util.ConverterUtil;
import com.thor.palmmall.rest.common.AAttachmentConverter;
import com.thor.palmmall.rest.common.AOperateInfoConverter;
import com.thor.palmmall.rest.common.AWorkOrderConverter;
import com.thor.palmmall.rest.servicebill.AServiceBill;
import com.thor.palmmall.spi.servicebill.SServiceBill;

/**
 * @author NuoSa
 *
 * @since 1.0
 */
public class AServiceBillConverter implements Converter<SServiceBill, AServiceBill> {

  public static AServiceBillConverter getInstance() {
    if (instance == null)
      instance = new AServiceBillConverter();
    return instance;
  }

  private static AServiceBillConverter instance;

  private AServiceBillConverter() {
  }

  @Override
  public AServiceBill convert(SServiceBill source) {
    if (source == null) {
      return null;
    }
    AServiceBill target = new AServiceBill();
    target.setUuid(source.getUuid());
    target.setVersion(source.getVersion());
    target.setVersionTime(source.getVersionTime());
    target.setCreateInfo(AOperateInfoConverter.getInstance().convert(source.getCreateInfo()));
    target
        .setLastModifyInfo(AOperateInfoConverter.getInstance().convert(source.getLastModifyInfo()));
    target.setPermGroupId(source.getPermGroupId());
    target.setPermGroupTitle(source.getPermGroupTitle());
    target.setBillNumber(source.getBillNumber());
    target.setBizState(source.getBizState());
    target.setBpmInstance(source.getBpmInstance());
    target.setBpmMessage(source.getBpmMessage());
    target.setBpmOutgoingState(source.getBpmOutgoingState());
    target.setBpmState(source.getBpmState());
    target.setAbortMsg(source.getAbortMsg());
    target.setStore(UCN.newInstance(source.getStore()));
    target.setContract(UCN.newInstance(source.getContract()));
    target.setTenant(UCN.newInstance(source.getTenant()));
    target.setRemark(source.getRemark());
    target.setServiceObject(source.getServiceObject());
    target.setContact(UCN.newInstance(source.getContact()));
    target.setContactInformation(source.getContactInformation());
    target.setServiceType(source.getServiceType());
    target.setProblemDescription(source.getProblemDescription());
    target.setAttachments(
        ConverterUtil.convert(source.getAttachments(), AAttachmentConverter.getInstance()));
    target.setWorkOrder(AWorkOrderConverter.getInstance().convert(source.getWorkOrder()));
    target.setType(source.getType());
    target.setHandler(source.getHandler());
    target.setBeginTime(source.getBeginTime());
    target.setSubmitTime(source.getSubmitTime());
    target.setApproveTime(source.getApproveTime());
    target.setApproveUser(source.getApproveUser());
    target.setApproveContent(source.getApproveContent());

    return target;
  }
}
